import {createRouter, createWebHistory} from 'vue-router'
import Login from '../views/LonginView.vue'


export const constantRoutes = [
    {
        path: '/',
        name: '/',
        component: () => import('../views/Index.vue')
    },
    {
        path: '/home',
        name: 'home',
        // route level code-splitting
        // this generates a separate chunk (About.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import('../views/AboutView.vue')
    },
    {
        path: '/login',
        name: 'login',
        component: Login
    }
]

export const notFont =
    {
        path: '/:pathMatch(.*)*',
        name: '404',
        component: () => import("../views/error/404.vue")
    }

const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes: constantRoutes,
    scrollBehavior(to, from, savePosition) {
        if (savePosition) {
            //解决页面从列表页跳转到详情页返回,初始在原来位置
            return savePosition
        } else {
            //解决页面跳转后页面高度和前一个页面高度一样
            return {x: 0, y: 0}
        }
    }
})

export default router
